#include <thread>
#include <chrono>
#include <iostream>
#include "log/DumpLog.h"

void test();
void testCostFun();

int main()
{
    //1.
    test();

    //2.
    if(true)
    {
        //在程序最后退出前,获取执行中设置的错误码
        auto exitCode = Log::DumpLog::getGlobalLog().waitExit();
        std::cout << "错误码是:" << (int)exitCode << "\n";
    }

    return 0;
}

void test()
{
    //1.设置日志输出到指定文件,如果不输出,则不设置
    Log::DumpLog::getGlobalLog().setLogFile("log.txt");

    //2. 日志打印测试
    LogInfo("这是日志第一行打印");
    LogInfo("x = {}, name = {}", 16, "我们");
    LogWarn("警告打印, z = {}", 15.89);
    LogError("错误级别打印");

    //3. 测试函数模块信息打印
    testCostFun();

    //4.
    constexpr uint16_t maxNum = 366;//数值范围为[0,366]
    LogInfo("开始测试进度条打印");
    BarInit(maxNum, "进度");//设置进度条最大值
    for (uint16_t i = 0; i != maxNum; ++i)
    {
        BarAddOne();//每次加1,等价于 BarAdd(1);
        std::this_thread::sleep_for(std::chrono::milliseconds(36));
    }
    LogInfo("结束测试进度条打印");

    //5.
    LogError("设置退出码:", Log::ExitCode_E::Error_E);
}

void testCostFun()
{
    ModuleFun //每个函数第一行代码加入[ModuleFun]将统计模块函数耗时以及运行时间
    for (int i = 0; i != 6; ++i)
    {
        LogInfo("index = {}", i);
        std::this_thread::sleep_for(std::chrono::milliseconds(500));
    }
}